package com.jasonchoi.security.commons;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @Author: JasonChoi
 * @Date: 2020/1/8 10:08
 */
@Data
@Accessors(chain = true)
public class RestResponse {
    private static final Integer OK = 200;
    private static final Integer ERROR = 9999;

    private Integer status;
    private String message;

    public static RestResponse ok(){
        return new RestResponse().setStatus(OK);
    }

    public static RestResponse error(){
        return new RestResponse().setStatus(ERROR);
    }

    public static RestResponse ok(String message){
        return RestResponse.ok().setMessage(message);
    }

    public static RestResponse error(String message){
        return RestResponse.error().setMessage(message);
    }

    public String toJson(){
        return JSONObject.toJSONString(this);
    }
}
